package com.lewin.ringroad.controller;

import com.lewin.commons.entity.LewinResult;
import com.lewin.ringroad.entity.RadarStatisticsDataVO;
import com.lewin.ringroad.service.IRadarService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 雷达数据接口控制器
 *
 * @author Jun
 * @since 1.0.0
 */
@RestController
@RequestMapping("/radar")
@CrossOrigin
public class RadarController {

    private final IRadarService radarService;

    public RadarController(IRadarService radarService) {
        this.radarService = radarService;
    }


    /**
     * @api {GET} /radar/statistics/{radarId} 雷达统计
     * @apiVersion 1.0.0
     * @apiGroup 雷达接口
     * @apiName statistics()
     * @apiParam (请求参数) {String} radarId 雷达 ID
     * @apiParamExample 请求参数示例
     * http://localhost:15689/radar/statistics/1
     * @apiSuccess (响应结果) {String} code
     * @apiSuccess (响应结果) {Array} data
     * @apiSuccess (响应结果) {Number} data.traffic 车流量
     * @apiSuccess (响应结果) {Number} data.averageSpeed 平均车速
     * @apiSuccess (响应结果) {Number} data.occupationRate 占有率
     * @apiSuccess (响应结果) {Number} data.queueLen 排队长度
     * @apiSuccess (响应结果) {String} data.timeAt 时间(yyyyMMddHH), 例: 2024020508
     * @apiSuccess (响应结果) {String} msg
     * @apiSuccessExample 响应结果示例
     * {"msg":"ZJBmo4Jg","code":"iYqc5qtqu","data":[{"queueLen":5649.61,"occupationRate":6269.12,"averageSpeed":288.44,"timeAt":"ia6NI","traffic":1924}]}
     */
    @GetMapping("/statistics/{radarId}")
    public LewinResult<List<RadarStatisticsDataVO>> statistics(@PathVariable String radarId){
        return radarService.statistics(radarId);
    }

    /**
     * @api {GET} /radar/line-statistics 环线统计
     * @apiVersion 1.0.0
     * @apiGroup 雷达接口
     * @apiName line()
     * @apiParam (请求参数) {String="east","north","west"} name 中环东西北线
     * @apiParamExample 请求参数示例
     * name=V4Eg&direct=2853
     * @apiSuccess (响应结果) {String} code
     * @apiSuccess (响应结果) {Array} data
     * @apiSuccess (响应结果) {Number} data.traffic 车流量
     * @apiSuccess (响应结果) {Number} data.averageSpeed 平均车速
     * @apiSuccess (响应结果) {Number} data.occupationRate 占有率
     * @apiSuccess (响应结果) {Number} data.queueLen 排队长度
     * @apiSuccess (响应结果) {String} data.timeAt 时间(yyyyMMddHH), 例: 2024020508
     * @apiSuccess (响应结果) {String} msg
     * @apiSuccessExample 响应结果示例
     * {"msg":"BJkcVSW","code":"zsY","data":[{"queueLen":9181.77,"occupationRate":2084.62,"averageSpeed":8888.37,"timeAt":"Sfve0se","traffic":6153}]}
     */
    @GetMapping("/line-statistics")
    public LewinResult<List<RadarStatisticsDataVO>> line(@RequestParam(defaultValue = "east") String name){
        return radarService.line(name);
    }
}
